<template>
	<view class="body">
		<block v-for="(message, index) in messageList.list" :key="index"><sys-message-item :type="type" :message="message"></sys-message-item></block>
	</view>
</template>

<script>
import sysMessageItem from '../../components/sys-massage/sys-message-item.vue';
import constant from '../../utils/Constant.js';
import showToast from '../../utils/ToastUtils.js';
export default {
	components: {
		sysMessageItem
	},
	data() {
		return {
			messageTypeInfo: {},
			type: '',
			messageList: {
				pageNo: 1,
				list: []
			}
		};
	},
	methods: {
		loadData(callBack) {
			uni.request({
				url: constant.baseHttpUri + constant.pathUri.noticeList,
				header: constant.authHead(),
				data: {
					pageNo: this.messageList.pageNo,
					type: this.type === 'ACCOUNT' ? 1 : this.type === 'SYS' ? 2 : 3
				},
				method: 'GET',
				success: res => {
					if (res.data.code === constant.dataCode.OK) {
						this.messageList.list.unshift(...res.data.data);
					} else {
						showToast(res.data.msg);
					}
				},
				fail: r => {
					console.log(r);
				},
				complete() {
					callBack && callBack();
				}
			});
		}
	},
	onLoad(options) {
		this.messageTypeInfo = JSON.parse(options.data);
		this.type = options.type;
		this.loadData();
	},
	onReady() {
		uni.setNavigationBarTitle({
			title: this.messageTypeInfo.nickName
		});
	},
	onPullDownRefresh() {
		this.messageList.pageNo+=1;
		this.loadData(()=>{
			uni.stopPullDownRefresh()
		});
	}
};
</script>

<style lang="less" scoped>
	
.body{
	border-top: 1rpx solid #CCCCCC;
}
</style>
